CPS_REPORT_CONFIG = {
    'real_time_report': True,
    'group_by': '_chn.keyword',
    'target_event_id': ['recharge', 'withdraw', 'active', 'register', 'bind_phone', 'cp_lottery', 'cp_game',
                        'platform_reward'],
    'values': [
        {
            "value_id": "new_device",
            "target_value": "_aid.keyword",
            "value_name": "新增设备",
            "filter": [
                {'terms': {'_event_id': ['active']}},
                {'term': {'_device_active_days': 0}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_register_device",
            "target_value": "_aid.keyword",
            "value_name": "新增注册设备",
            "filter": [
                {'terms': {'_event_id': ['bind_phone']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_user",
            "target_value": "_user_id",
            "value_name": "新增用户",
            "filter": [
                {'terms': {'_event_id': ['register']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_register_user",
            "target_value": "_user_id",
            "value_name": "新增注册用户",
            "filter": [
                {'terms': {'_event_id': ['bind_phone']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "active_device",
            "target_value": "_aid.keyword",
            "value_name": "活跃设备",
            "filter": [
                {'terms': {'_event_id': ['active']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "active_user",
            "target_value": "_user_id",
            "value_name": "活跃用户",
            "filter": [
                {'terms': {'_event_id': ['active']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "register_rate",
            "value_name": "当天注册率",
            "value_expr": "new_register_user/new_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_amount",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
        },
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "recharge_rate",
            "value_name": "付费率",
            "value_expr": "recharge_user/active_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "new_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "新增充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
        },
        {
            "value_id": "new_recharge_user",
            "target_value": "_user_id",
            "value_name": "新增充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_recharge_rate",
            "value_name": "新用户付费率",
            "value_expr": "new_recharge_user/new_register_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "next_day_device",
            "target_value": "_aid.keyword",
            "value_name": "设备次留数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "next_day_user",
            "target_value": "_user_id",
            "value_name": "用户次留数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "lottery_bet_amount",
            "target_value": "cp_lottery_price",
            "value_name": "购彩流水",
            "filter": [
                {'terms': {'_event_id': ['cp_lottery']}},
                {'term': {'cp_lottery_refund': 0}}
            ],
            "value_type": "float"
        },
        {
            "value_id": "lottery_win_amount",
            "target_value": ["cp_lottery_bonus", "+", "cp_lottery_win"],
            "value_name": "购彩中奖",
            "filter": [
                {'terms': {'_event_id': ['cp_lottery']}},
            ],
            "value_type": "float"
        },
        {
            "value_id": "dwc_bet_amount",
            "target_value": ["cp_game_price"],
            "value_name": "总电玩城流水",
            "filter": [
                {'terms': {'_event_id': ['cp_game']}},
            ],
            "value_type": "float"
        },
        {
            "value_id": "dwc_win_amount",
            "target_value": ["cp_game_win"],
            "value_name": "总电玩城中奖",
            "filter": [
                {'terms': {'_event_id': ['cp_game']}},
            ],
            "value_type": "float"
        },
        {
            "value_id": "platform_reward_amount",
            "target_value": "platform_reward_reward_amount",
            "value_name": "活动奖励",
            "filter": [
                {'term': {'_event_id': 'platform_reward'}}
            ],
            "value_type": "float"
        },
        {
            "value_id": "total_profit",
            "value_name": "利润",
            "value_expr": "lottery_bet_amount + dwc_bet_amount - lottery_win_amount - dwc_win_amount",
            "value_type": "float"
        }
    ]
}
